
<?php
	 require_once("newSearch.php");
	 function downloadFile($file)
	 {
		  if(!file_exists($file)){   //检查文件是否存在  
			  echo   "Can't find file:".$file;  
			  exit;    
		  }   
		  else 
		  {  
			 header ( 'Content-Description: File Transfer' );
			 header ( 'Content-Type: application/octet-stream' );
			 header ( 'Content-Disposition: attachment; filename=' . basename ( $file ));
			 header ( 'Content-Transfer-Encoding: binary' );
			 header ( 'Expires: 0' );
			 header ( 'Cache-Control: must-revalidate' );
			 header ( 'Pragma: public' );
			 header ( 'Content-Length: '  .  filesize ( $file ));
			 ob_clean ();
			 flush ();
			 readfile ( $file );
		  }
	 }
	 @session_start();
	if(!empty($_POST['exportItems']) && !empty($_POST['export_type']) && !empty($_POST['export_sql'])){
				
				 header( "refresh:1;url=downloadResult.php" ); 
				 if(stristr($_POST['export_type'],"w")){
					
					echo "Exporting...".EOL;
					getPapersFromMysql($_POST['export_sql'],$content,true,false,$_POST['export_type']);
					
				 }
				 else{
					 echo "Exporting...".EOL;
					 getPapersFromMysql($_POST['export_sql'],$content,true,false,$_POST['export_type']);
				 }
				 $_SESSION['download']=$_POST['export_type'];
				  
	 }
	 else  if(!empty($_SESSION['download'])){
		
		if(stristr($_SESSION['download'],"w"))
		{
			$path=dirname(__FILE__)."/WriteWord/result.doc";
		}
		else{
			$path=dirname(__FILE__)."/searchResult/result.xls";	
		}
		downloadFile($path);
		
		unset($_SESSION['download']);
		
	 }
	 else{
		
		echo "Failed to export".EOL;
	 }
?>
